



//% color="#ff4a36" iconWidth=50 iconHeight=40
namespace miniewa12DOF{
	
	//初始化猫形机器人
	//% block="Cat shaped robot initialization serial RX[rxpin1] TX[txpin1]" blockType="command"
	//%rxpin1.shadow="dropdown" rxpin1.options="cat_softwareserialrx" rxpin1.defl="cat_softwareserialrx.2"
	//%txpin1.shadow="dropdown" txpin1.options="cat_softwareserialtx" txpin1.defl="cat_softwareserialtx.A3"
	export function initialization(parameter: any, block: any) {
        let pin_rx = parameter.rxpin1.code;
        let pin_tx = parameter.txpin1.code;
		Generator.addInclude(`softwareSerialinclude`,`#include <SoftwareSerial.h>`,true);
		Generator.addInclude(`servoinclude`,`#include <Servo.h>`,true);
		Generator.addInclude(`CatRobotinclude`,`#include <CatRobot.h>`,true);
		Generator.addObject(`softwareSerial1`,`SoftwareSerial`,`softwareSerial1(${pin_rx}, ${pin_tx})`,true);
		Generator.addObject(`robot`,`CatRobot`,`robot`,true);
		Generator.addObject(`t`,`String`,`t`,true);
		Generator.addObject(`randnumber`,`int`,`randnumber`,true);
		Generator.addSetup(`Serialbegin`,`Serial.begin(9600);`,true);
		Generator.addSetup(`Serial1begin`,`softwareSerial1.begin(9600);`,true);
		Generator.addSetup(`robot_initServos`,`robot.initServos();`,true);
		Generator.addSetup(`yanshi1`,`delay(5000);`,true);
		}

	//猫形机器人前进
	//% block="forwardcreep" blockType="command"
	export function forwardcreep(parameter: any, block: any) {
		Generator.addCode(`robot.forwardcreep();`);
	}

	//猫形机器人后退
	//% block="freversecreep" blockType="command"
	export function reversecreep(parameter: any, block: any) {
		Generator.addCode(`robot.reversecreep();`);
	}	
	
	//猫形机器左转
	//% block="leftturn" blockType="command"
	export function leftturn(parameter: any, block: any) {
		Generator.addCode(`robot.leftturn();`);
	}	
	
	//猫形机器右转
	//% block="rightturn" blockType="command"
	export function rightturn(parameter: any, block: any) {
		Generator.addCode(`robot.rightturn();`);
	}	
	
	//猫形机器踢腿
	//% block="kick" blockType="command"
	export function kick(parameter: any, block: any) {
		Generator.addCode(`robot.kick();`);
	}

	//随机一段舞蹈
	//% block="random dance" blockType="command"
	export function suijiwudao(parameter: any, block: any) {
		Generator.addCode(`randnumber = random(1, 4);`);
		Generator.addCode(`if (randnumber == 1) {`);
		Generator.addCode(`\r\trobot.dance1();`);
		Generator.addCode(`} else if (randnumber == 2) {`);
		Generator.addCode(`\r\trobot.dance2();`);
		Generator.addCode(`} else if (randnumber == 3) {`);
		Generator.addCode(`\r\trobot.dance3();`);
		Generator.addCode(`}`);
		
	}	
	
	//猫形机器第一段舞蹈
	//% block="dance1" blockType="command"
	export function dance1(parameter: any, block: any) {
		Generator.addCode(`robot.dance1();`);
	}
	
	//猫形机器第二段舞蹈
	//% block="dance2" blockType="command"
	export function dance2(parameter: any, block: any) {
		Generator.addCode(`robot.dance2();`);
	}
	
	//猫形机器第三段舞蹈
	//% block="dance3" blockType="command"
	export function dance3(parameter: any, block: any) {
		Generator.addCode(`robot.dance3();`);
	}
	
	//猫形机器握手
	//% block="handShake" blockType="command"
	export function handShake(parameter: any, block: any) {
		Generator.addCode(`robot.handShake();`);
	}
	
	//猫形机器坐下
	//% block="sit" blockType="command"
	export function sit(parameter: any, block: any) {
		Generator.addCode(`robot.sit();`);
	}
	
	//猫形机器站立
	//% block="stand" blockType="command"
	export function stand(parameter: any, block: any) {
		Generator.addCode(`robot.stand();`);
	}
	
	//软串口是否有数据？
	//% block="chuankoushifouyoushuju" blockType="boolean"
	export function chuankoushifouyoushuju(parameter: any, block: any) {
		Generator.addCode(`softwareSerial1.available()`);
	}
	
	//读取串口数据
	//% block="duquchuankushuju" blockType="command"
	export function duquchuankushuju(parameter: any, block: any) {
		Generator.addCode(`t = String(char(softwareSerial1.read()));`);
	}
	
	//串口数据是否等于?
	//% block="Serial message equals [message]" blockType="boolean"
	//%message.shadow="string"  message.defl="F"
	export function chuankushuju(parameter: any, block: any) {
		let messages = parameter.message.code;
		Generator.addCode(`t == ${messages}`);
	}
	
	
	
	
   
	
	
	
	
	
}
